<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>失效资源管理_资源共享平台</title>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
</head>
<body>
<div th:include="common/header" class="header-wrapper"></div>
<div class="container-wrapper">
    <div th:include="common/menu" class="menu-left"></div>
    <div class="menu-right">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>失效资源管理</legend>
        </fieldset>
        <table id="resListTable" lay-filter="resListTable"></table>
    </div>
</div>
<div th:include="common/link" class="wrapper"></div>
<div th:include="common/footer" class="footer-wrapper"></div>

<script type="text/html" id="toolTpl">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修复链接</a>
</script>

<script src="/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    let $, layer, table;
    layui.use(['layer', 'element', 'table'], function () {
        $ = layui.jquery;
        layer = layui.layer;
        table = layui.table;

        table.render({
            elem: '#resListTable',
            url: '/res/userResList',
            where: {
                useful: false
            },
            cols: [[
                {type: 'checkbox'},
                {field: 'name', title: '资源名称', templet: formatName},
                {field: 'publishDate', width: 180, title: '发布日期', sort: true, align: 'center'},
                {field: 'action', width: 150, title: '操作', align: 'center', templet: '#toolTpl'}
            ]],
            page: true
        });

        // 触发单元格工具事件
        table.on('tool(resListTable)', function (obj) {
            let data = obj.data; // 获得当前行数据
            switch (obj.event) { // 获得 lay-event 对应的值
                case 'edit': // 修复链接
                    layer.open({
                        type: 2,
                        title: '修改百度云分享链接',
                        area: ['500px', '300px'],
                        content: '/res/modifyShareLink.html',
                        success: function (layero, index) {
                            let body = layer.getChildFrame('body',index);
                            //获取子页面的元素，进行数据渲染
                            body.contents().find("#id").val(data.id);
                        }
                    });
                    break;
            }
        });
    });

    function formatName(d) {
        if (d.checkStatus == 2) {
            return '<a href="/res/detail/' + d.id + '" target="_blank">' + d.name + '</a>';
        } else {
            return d.name;
        }
    }

    /*]]>*/
</script>
</body>
</html>